import time

from selenium.webdriver.common.by import By

from common.Utils import BlogDriver

class BlogDetail:
    url=""
    driver=""
    def __init__(self):
        self.url="http://8.137.19.140:9090/blog_detail.html?blogId=25492"
        self.driver=BlogDriver.driver
        self.driver.get(self.url)

    def BlogDetailTest(self):
        #检查标题是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div > div.title")
        #检查内容是否存在
        self.driver.find_element(By.CSS_SELECTOR,"#h2-u5728u8FD9u91CCu5199u4E0Bu4E00u7BC7u535Au5BA2")
        #检查时间是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div > div.date")

        #检查编辑按钮是否存在，是否可以跳转到编辑页面
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div > div.operating > button:nth-child(1)").click()
        excepted_url="http://8.137.19.140:9090/blog_update.html?blogId=25492"
        current_url=self.driver.current_url
        if current_url==excepted_url:
            print(f"编辑按钮跳转成功！")
        else:
            print(f"编辑按钮跳转失败！")
        self.driver.back()

        #检查删除按钮，是否调起提示弹窗
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div > div.operating > button:nth-child(2)").click()
        time.sleep(2)
        alert=self.driver.switch_to.alert
        alert.dismiss()

        #添加屏幕截图
        BlogDriver.getScreenShot()